package com.yaorange.guild.association.service.impl;

import com.yaorange.guild.association.entity.BsAssociation;
import com.yaorange.guild.association.mapper.BsAssociationMapper;
import com.yaorange.guild.association.service.BsAssociationService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 协会信息Service实现类
 */
@Service
public class BsAssociationServiceImpl implements BsAssociationService {

    @Resource
    private BsAssociationMapper bsAssociationMapper;


    /**
     * 插入协会信息
     */
    @Override
    public int insert(BsAssociation association) {
        return bsAssociationMapper.insert(association);
    }

    /**
     * 根据主键更新协会信息
     */
    @Override
    public int updateById(BsAssociation association) {
        return bsAssociationMapper.updateById(association);
    }

    /**
     * 获取单条记录
     * @return
     */
    @Override
    public BsAssociation getOne() {
        //首先尝试查询
        List<BsAssociation> list = bsAssociationMapper.selectAll(new BsAssociation());
        //如果不存在则新增一条空的新纪录
        if (list.isEmpty()){
            BsAssociation bsAssociation = new BsAssociation();
            this.insert(bsAssociation);
            return bsAssociation;
        }
        return list.get(0);
    }

}
